﻿using System;
using System.Net;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Info;

namespace nyxwin.Data.Utils
{
	public static class UserDeviceIdentity
	{
		#region Properties

        public static string UserAgent
        {
            get
            {
                return string.Format("nyxPhone/nyxWin v0.1.0; {0} - {1}", UserDeviceIdentity.Name, UserDeviceIdentity.UniqueId.Substring(0, 4) /* 4 digz is enough */);
            }
        }

		#region Manufacturer
		public static string Manufacturer
		{
			get
			{
				var result = string.Empty;

				object manufacturer = null;
				if (DeviceExtendedProperties.TryGetValue("DeviceManufacturer", out manufacturer))
					result = manufacturer.ToString();

				return result;
			}
		}
		#endregion

		#region Name
		public static string Name
		{
			get
			{
				var result = string.Empty;

				object name = null;
				if (DeviceExtendedProperties.TryGetValue("DeviceName", out name))
					result = name.ToString();

				return result;
			}
		}
		#endregion

		#region UniqueId
		public static string UniqueId
		{
			get
			{
				var sb = new StringBuilder();

				object deviceUniqueId = null;
				if (DeviceExtendedProperties.TryGetValue("DeviceUniqueId", out deviceUniqueId))
				{
					var buf = (byte[])deviceUniqueId;
					foreach (var b in buf)
						sb.Append(b.ToString("x2"));
				}

				return sb.ToString();
			}
		}
		#endregion

		#endregion
	}
}
